/* Original Author:  Dominick O'Dierno
 * Date: 2007   odiernod@gmail.com     --Originally intended for use with DOMercury:  http://www.odierno.com/domercury
 * Description: Manager handling the actual execution of the IAction on the IItem with any parameters
 * 
 * --CHANGELOG--
 * 
 * */
using System;
using System.Collections.Generic;
using System.Text;
using DOMercury.Interfaces;
using ManagedWinapi.Windows;

namespace DOMercury.Managers
{
    class ActionManager
    {
        private static SystemWindow fWindow;

        public static SystemWindow ForegroundWindow
        {
            get
            {
                return fWindow;
            }
            set
            {
                fWindow = value;
            }
        }

        public static bool Perform(IItem Item, IAction Action, object specialParams)
        {
            bool result = false;
            if (Action != null)
            {
                switch (Action.ParameterType)
                {
                    case "SendTo":
                        //result = Action.Perform(Item, AutoCompleteManager.GetSendToPath((string)specialParams));
                        break;
                    case "Hwnd":
                        result = Action.Perform(Item, fWindow.HWnd);
                        break;
                    default:
                        if (specialParams.GetType() == typeof(Items.TextItem))
                        {
                            result = Action.Perform(Item, ((IItem)(specialParams)).DisplayName);
                            IndexManager.AddToParamHistory(((IItem)(specialParams)).DisplayName);
                        }
                        else
                        {
                            result = Action.Perform(Item, specialParams);
                            if (specialParams.GetType() == typeof(string))
                            {
                                IndexManager.AddToParamHistory((string)specialParams);
                            }
                        }
                        break;
                }
            }
            if (Item != null)
            {
                IndexManager.IncreasePriority(Item.DisplayName, Item.DisplayDesc);

                if (Item.GetType() == typeof(Items.TextItem))
                {
                    IndexManager.AddToItemHistory((Items.TextItem)Item);
                }
            }
            if (result)
            {
                IndexManager.ReturnMainIndex();
            }
            IndexManager.SortIndex();
            IndexManager.SavePriorities();
            return result;
        }
    }
}
